$(function() {
	$.ajax({
		type: "post",
		url: "http://a.91jfk.com/Product/Order/goods_luck",
		data: {},
		dataType: 'json',
		success: function(res) {
			console.log(res);
			for(var i = 0; i < res.msg.length; i++) {
				var qishu = getDate(res.msg[i].qishu - 0);
				showItem(res.msg[i].thumbnail, res.msg[i].pname, qishu, res.msg[i].create_time,i);
				if(res.msg[i].state == 1){
					$(".winning_img" + i).attr('src','/Public/Product/img/xuanzhong.png');
					$(".address_img" + i).attr('src','/Public/Product/img/xuanzhong.png');
					$(".deliver_img" + i).attr('src','/Public/Product/img/weixuanzhong.png');
					$(".winning" + i).css('color','#8e6cd1');
					$(".address" + i).css('color','#8e6cd1');
					$(".deliver" + i).css('color','#898989');
					$(".progress_left" + i).css('color',"#8e6cd1");
					$(".progress_right" + i).css('color',"#dddddd");
				}else if(res.msg[i].state == 2){
					$(".winning_img" + i).attr('/Public/Product/img/xuanzhong.png');
					$(".address_img" + i).attr('/Public/Product/img/xuanzhong.png');
					$(".deliver_img" + i).attr('/Public/Product/img/xuanzhong.png');
					$(".winning" + i).css('color','#8e6cd1');
					$(".address" + i).css('color','#8e6cd1');
					$(".deliver" + i).css('color','#8e6cd1');
					$(".progress_left" + i).css('color',"#8e6cd1");
					$(".progress_right" + i).css('color',"#8e6cd1");
				}else{
					$(".winning_img" + i).attr('src','/Public/Product/img/xuanzhong.png');
					$(".address_img" + i).attr('src','/Public/Product/img/weixuanzhong.png');
					$(".deliver_img" + i).attr('src','/Public/Product/img/weixuanzhong.png');
					$(".winning" + i).css('color','#8e6cd1');
					$(".address" + i).css('color','#898989');
					$(".deliver" + i).css('color','#898989');
					$(".progress_left" + i).css('color',"#dddddd");
					$(".progress_right" + i).css('color',"#dddddd");
				}
			}
			//设置总数
	$(".title span").text($(".list").length);
		},
		error: function(err) {
			console.log(err)
		}
	});
	//没有确认地址的时候
	function showItem(src, pname, qishu, time,i) {
		var prize_content = $(".prize");
		var list = $('<div class="list"><div class="left"><img src="' + src + '" style="height: 1.866666rem;width: 1.866666rem;" /></div><div class="right"><p>' + pname + '</p><p>商品期数:' + qishu + '</p><p>揭晓时间:' + time + '</p></div><div class="bottom"><img src="/Public/Product/img/xuanzhong.png" class="winning_img winning_img' + i + '" /><div class="progress_left progress_left' + i + '">•••••••••••••••••••••••••••••••••</div><img src="/Public/Product/img/weixuanzhong.png"  class="address_img address_img' + i + '" /><div class="progress_right progress_right' + i +'">•••••••••••••••••••••••••••••••••</div><img src="/Public/Product/img/weixuanzhong.png" class="deliver_img deliver_img' + i + '"/></div><p class="speed"><span class="winning winning' + i + '">中奖了</span><span class="address address' + i + '">确认地址</span><span class="deliver deliver' + i + '">发货</span></p></div>');
		prize_content.append(list);
	}
	
	
	
	//让个位数前边添0	
	function add0(m) {
		return m < 10 ? '0' + m : m
	}
	//将时间戳转化为具体具体时间，中间不带空格和横线的
	function getDate(shijianchuo) {
		//shijianchuo是整数，否则要parseInt转换  
		var time = new Date(shijianchuo);
		var y = time.getFullYear();
		var m = time.getMonth() + 1;
		var d = time.getDate();
		var h = time.getHours();
		var mm = time.getMinutes();
		var s = time.getSeconds();
		return y + '' + add0(m) + '' + add0(d) + '' + add0(h) + '' + add0(mm) + '' + add0(s);
	};
})